package test_junit_shop.ManageShop;

import org.apache.bcel.generic.Select;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.util.Random;

/**
 * Created by ZH on 2018/2/8.
 * 门店-工位管理新增
 */
public class AddWorkArea {
    private static AddWorkArea awa = new AddWorkArea();
    private WebDriver driver;
    public static AddWorkArea getInstance(){
        return awa;
    }
    public WebDriver getwDriver(){
        return driver;
    }
    public void setwDriver(WebDriver w){
        driver = w;
    }

    private String flag = "0";

    public void addWorkArea() throws InterruptedException {
        Random random = new Random();
        int i = 3;
        while (i-- > 0){
            flag += random.nextInt(10);
        }

        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/iframe")));
        driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div/div[3]/ul/li[2]/i")).click();
        driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div/div[3]/ul/li[2]/ul/li/a")).click();
        Thread.sleep(2000);
        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div/div[2]/iframe")));
        Thread.sleep(1000);
        driver.findElement(By.id("add_btn")).click();
        driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div/div[2]/ul/li[1]/input")).sendKeys("测试工位"+flag);
        org.openqa.selenium.support.ui.Select s = new org.openqa.selenium.support.ui.Select(driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div/div[2]/ul/li[1]/p/select")));
        s.selectByVisibleText("使用中");
        Thread.sleep(2000);
        driver.findElement(By.xpath("/html/body/div[2]/div/div/div/div/div[2]/ul/li[1]/div/button[1]")).click();

        driver.switchTo().defaultContent();
        driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content-main\"]/iframe[2]")));
        Thread.sleep(1000);
        driver.findElement(By.xpath("/html/body/div[4]/div[3]/a")).click();
    }
}
